export default {
	namespaced: true,
	state: () => ({
		// 收货地址
		address: JSON.parse(uni.getStorageSync('address') || '{}'),
		// 用户的基本信息
		userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		// 登录成功后的token字符串
		token: uni.getStorageSync('token') || '',
		// 重定向
		redirectInfo: null
	}),
	getters: {
		addstr(state) {
			if (!state.address.provinceName) return ''
			return state.address.provinceName + state.address.cityName + state.address.countyName + state
				.address
				.detailInfo
		}
	},
	mutations: {
		// 更新收货地址
		updateAddress(state, address) {
			state.address = address;
			this.commit('m_user/saveAddressToStorage')
		},
		saveAddressToStorage(state) {
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		// 更新用户的基本信息
		updateUserInfo(state, userinfo) {
			state.userinfo = userinfo
			this.commit('m_user/saveUserInfoStorage')
		},
		saveUserInfoStorage(state) {
			uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
		},
		// 更新token值
		updateToken(state, _token) {
			state.token = _token
			this.commit('m_user/saveUpdateToken')
		},
		saveUpdateToken(state) {
			uni.setStorageSync('token', JSON.stringify(state.token))
		},
		// 更新重定向信息
		updateRedirectInfo(state, info) {
			state.redirectInfo = info
		}
	}
}
